package org.yyjkcache.tasks;

import org.yyjkcache.cache.DefaultCache;
import org.yyjkcache.common.HttpGetRequest;
import org.yyjkcache.common.JedisLinkedPool;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class MemoryUsedTask implements Task {
    private static String prefix="http://10.1.16.153:28081/ai-background/tpm/account/9/applications/";
    private static String suffix="/stats/detail.json?spanTime=60000&interval=6000&start=0&limit=5&orderBy=ORDERBY_S1_DESC&name=MemoryUsed&tierId=";
    @Override
    public void save() {
        List<Object> list = DefaultCache.cache().getContents("Ailist");
        Map<String, Object> map = null;
        String json = null;
        StringBuilder builder = null;
        String systemid = null;
        String jsons[]=new String[list.size()];
        int index=0;
        for (Object object : list) {
            try {
                map = (Map<String, Object>) object;
                builder = new StringBuilder();
                systemid = String.valueOf(map.get("systemId"));
                builder.append(prefix).append(systemid).append(suffix).append(systemid);
                json = HttpGetRequest.reuest().getRemoteJSON(builder.toString());
                jsons[index]=json;
            } catch (IOException e) {
                e.printStackTrace();
            }
            ++index;
        }
        JedisLinkedPool.pool().listPush("MemoryUsed",jsons);
    }
}
